```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring MVC拦截器与过滤器深度解析 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #9333ea 100%);
        }
        .code-block {
            background-color: #282c34;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 0.2em;
            left: 0;
            width: 100%;
            height: 0.3em;
            background-color: rgba(79, 70, 229, 0.3);
            z-index: -1;
            border-radius: 2px;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-6xl font-bold mb-6 animate-fade-in-down">Spring MVC拦截器与过滤器</h1>
            <p class="text-xl md:text-2xl text-indigo-100 max-w-3xl mx-auto mb-8">深入理解请求处理流程中的关键组件</p>
            <div class="flex justify-center space-x-4">
                <a href="#comparison" class="bg-white text-indigo-700 hover:bg-indigo-50 px-6 py-3 rounded-lg font-medium transition duration-300 transform hover:scale-105">核心区别</a>
                <a href="#implementation" class="bg-indigo-800 hover:bg-indigo-700 text-white px-6 py-3 rounded-lg font-medium transition duration-300 transform hover:scale-105">实现方式</a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12 md:py-16">
        <!-- Comparison Section -->
        <section id="comparison" class="mb-20">
            <div class="text-center mb-12">
                <h2 class="text-3xl md:text-4xl font-bold mb-4 text-gray-800">核心区别</h2>
                <p class="text-gray-600 max-w-3xl mx-auto">HandlerInterceptor 和 Filter 在 Spring MVC 中的定位与作用范围</p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-8 rounded-xl shadow-lg card-hover border-t-4 border-indigo-500">
                    <div class="flex items-center mb-6">
                        <div class="bg-indigo-100 text-indigo-700 p-3 rounded-full mr-4">
                            <i class="fas fa-project-diagram text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">HandlerInterceptor</h3>
                    </div>
                    <ul class="space-y-4 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-3"></i>
                            <span>Spring MVC 特有的组件</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-3"></i>
                            <span>作用于控制器执行的前后及视图渲染前后</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-3"></i>
                            <span>可以访问 Spring 上下文和模型数据</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-3"></i>
                            <span>通过 WebMvcConfigurer 注册</span>
                        </li>
                    </ul>
                </div>

                <div class="bg-white p-8 rounded-xl shadow-lg card-hover border-t-4 border-purple-500">
                    <div class="flex items-center mb-6">
                        <div class="bg-purple-100 text-purple-700 p-3 rounded-full mr-4">
                            <i class="fas fa-filter text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">Filter</h3>
                    </div>
                    <ul class="space-y-4 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <span>Servlet 规范的标准组件</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <span>作用于整个 Servlet 容器</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <span>无法直接访问 Spring 上下文</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-3"></i>
                            <span>通过 web.xml 或 @WebFilter 注册</span>
                        </li>
                    </ul>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-lg overflow-hidden mb-12">
                <div class="p-6 md:p-8">
                    <h3 class="text-2xl font-bold mb-6 text-gray-800">执行流程对比</h3>
                    <div class="mermaid">
                        graph LR
                            A[客户端请求] --> B[FilterChain]
                            B --> C[DispatcherServlet]
                            C --> D[HandlerInterceptor.preHandle]
                            D --> E[Controller]
                            E --> F[HandlerInterceptor.postHandle]
                            F --> G[视图渲染]
                            G --> H[HandlerInterceptor.afterCompletion]
                            H --> B
                            B --> I[客户端响应]
                    </div>
                </div>
            </div>
        </section>

        <!-- Implementation Section -->
        <section id="implementation" class="mb-20">
            <div class="text-center mb-12">
                <h2 class="text-3xl md:text-4xl font-bold mb-4 text-gray-800">实现自定义拦截器链</h2>
                <p class="text-gray-600 max-w-3xl mx-auto">如何创建和配置 HandlerInterceptor 和 Filter</p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white p-6 rounded-xl shadow-lg">
                    <div class="flex items-center mb-6">
                        <div class="bg-indigo-100 text-indigo-700 p-3 rounded-full mr-4">
                            <i class="fas fa-code text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">自定义 HandlerInterceptor</h3>
                    </div>
                    <div class="code-block p-4 rounded-lg mb-4">
                        <pre class="text-gray-300 text-sm"><code>public class CustomInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, 
            HttpServletResponse response, Object handler) {
        // 请求处理前逻辑
        return true; // 继续执行或终止
    }

    @Override
    public void postHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler, 
            ModelAndView modelAndView) {
        // 请求处理后逻辑
    }

    @Override
    public void afterCompletion(HttpServletRequest request,
            HttpServletResponse response, Object handler, 
            Exception ex) {
        // 请求完成逻辑
    }
}</code></pre>
                    </div>
                    <div class="p-4 bg-indigo-50 rounded-lg">
                        <h4 class="font-bold text-indigo-700 mb-2">注册拦截器</h4>
                        <div class="code-block p-4 rounded-lg">
                            <pre class="text-gray-300 text-sm"><code>@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new CustomInterceptor())
                .addPathPatterns("/**");
    }
}</code></pre>
                        </div>
                    </div>
                </div>

                <div class="bg-white p-6 rounded-xl shadow-lg">
                    <div class="flex items-center mb-6">
                        <div class="bg-purple-100 text-purple-700 p-3 rounded-full mr-4">
                            <i class="fas fa-code text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">自定义 Filter</h3>
                    </div>
                    <div class="code-block p-4 rounded-lg mb-4">
                        <pre class="text-gray-300 text-sm"><code>public class CustomFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) {
        // 初始化逻辑
    }

    @Override
    public void doFilter(ServletRequest request, 
            ServletResponse response, FilterChain chain) {
        // 请求处理逻辑
        chain.doFilter(request, response);
        // 响应处理逻辑
    }

    @Override
    public void destroy() {
        // 销毁逻辑
    }
}</code></pre>
                    </div>
                    <div class="p-4 bg-purple-50 rounded-lg">
                        <h4 class="font-bold text-purple-700 mb-2">注册过滤器</h4>
                        <div class="code-block p-4 rounded-lg">
                            <pre class="text-gray-300 text-sm"><code>@Configuration
public class AppConfig {
    @Bean
    public FilterRegistrationBean&lt;CustomFilter&gt; loggingFilter() {
        FilterRegistrationBean&lt;CustomFilter&gt; bean = 
            new FilterRegistrationBean<>();
        bean.setFilter(new CustomFilter());
        bean.addUrlPatterns("/*");
        return bean;
    }
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Key Points Section -->
        <section class="bg-indigo-50 rounded-xl p-8 md:p-12 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-indigo-800">关键概念</h2>
            <div class="grid md:grid-cols-2 gap-6">
                <div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">何时使用 HandlerInterceptor？</h3>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-3"></i>
                            <span>需要访问 Spring 上下文和模型数据时</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-3"></i>
                            <span>需要在控制器执行前后添加逻辑时</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-3"></i>
                            <span>需要在视图渲染前后处理时</span>
                        </li>
                    </ul>
                </div>
                <div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">何时使用 Filter？</h3>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-3"></i>
                            <span>需要对所有请求进行预处理时</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-3"></i>
                            <span>不依赖 Spring 上下文的基础功能时</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-indigo-500 mt-1 mr-3"></i>
                            <span>需要处理静态资源请求时</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">深入浅出技术原理，构建高效开发思维</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-300 hover:text-white transition duration-200 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        <span>www.yuque.com/jtostring</span>
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```